﻿Imports System.Net
Imports System.Net.Sockets

Namespace EIB.Bus
    Public NotInheritable Class EIBBusAccessModule_KNXNetIP_Routing 'Routing
        Implements IEIBBusAccessModule

        Public Event LogBusData(reason As EIBBusAccessLogReason, message As String, data() As Byte) Implements IEIBBusAccessModule.LogBusData
        Public Event ReceiveBusData(address As Addressing.EIBAddress, value() As Byte) Implements IEIBBusAccessModule.ReceiveBusData

        Private _RemoteEndpoint As IPEndPoint = Nothing
        Private _LocalEndpoint As IPEndPoint = Nothing
        Private _UDPClient As UdpClient = Nothing


        Public Function OpenConnection(ParamArray params() As Object) As Boolean Implements IEIBBusAccessModule.OpenConnection
            Dim host As String = ""
            Dim port As Integer = 0

            If params Is Nothing OrElse params.Count = 0 Then
                host = "224.0.23.12"
                port = 3671
            ElseIf params.Count = 1 Then
                host = params(0)
            ElseIf params.Count = 2 Then
                host = params(0)
                port = params(1)
            Else
                Throw New EIB.Exceptions.EIBException("")
            End If

            Dim ip As IPAddress = IPAddress.Parse(host)
            _RemoteEndpoint = New IPEndPoint(ip, port)
            _LocalEndpoint = New IPEndPoint(IPAddress.Any, 0)

            _UDPClient = New UdpClient(port)
            _UDPClient.JoinMulticastGroup(ip)


            Return True
        End Function

        Public Sub CloseConnection() Implements IEIBBusAccessModule.CloseConnection

        End Sub

        Public ReadOnly Property IsConnected As Boolean Implements IEIBBusAccessModule.IsConnected
            Get

            End Get
        End Property


        Public Sub ReadBusData(address As Addressing.EIBGroupAddress) Implements IEIBBusAccessModule.ReadBusData

        End Sub

        Public Sub RespondBusData(address As Addressing.EIBGroupAddress, value() As Byte) Implements IEIBBusAccessModule.RespondBusData

        End Sub

        Public Sub WriteBusData(address As Addressing.EIBGroupAddress, value() As Byte) Implements IEIBBusAccessModule.WriteBusData

        End Sub


        Public Function ResetBCU() As Boolean Implements IEIBBusAccessModule.ResetBCU

        End Function

        Public Sub GetLinkStatus() Implements IEIBBusAccessModule.GetLinkStatus

        End Sub
    End Class
End Namespace
